/** 
 * 
 * @author geloin 
 * @date 2012-5-5 上午9:31:52 
 */
package com.controller;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.Util.RequestUtil;
import com.Util.ResponseUtil;
import com.entity.RequestBean;
import com.entity.SubGridBean;
import com.entity.TableDataBean;
import com.entity.TestBean;
import com.service.GetTimeService;



@Controller
public class GetDataController {
	@Resource(name = "GetTimeService")
	private GetTimeService getTimeService;
	
	@RequestMapping("/ueditor")
	public ModelAndView ueditor(){
		ModelAndView mav = new ModelAndView();
		mav.setViewName("/highchartsPage/column-basic");
		mav.addObject("data", "大家好，我是contact");
		return mav;
	}
	
	@RequestMapping("/column-basic")
	public ModelAndView columnBasic(){
		ModelAndView mav = new ModelAndView();
		mav.setViewName("/highchartsPage/column-basic");
		mav.addObject("data", "大家好，我是contact");
		return mav;
	}
	
	
	
	
	
	
	
	
	@RequestMapping("/contact")
	public ModelAndView contact(){
		ModelAndView mav = new ModelAndView();
		mav.setViewName("contact");
		mav.addObject("data", "大家好，我是contact");
		return mav;
	}
	@RequestMapping("/u")
	public ModelAndView u(){
		
		ModelAndView mav = new ModelAndView();
		mav.setViewName("u");
		mav.addObject("data", "大家好，我是u");
		return mav;
	}
	@RequestMapping("/getTime")
	public ModelAndView getTime(){
		String s = getTimeService.fun();
		ModelAndView mav = new ModelAndView();
		mav.setViewName("contact");
		mav.addObject("data", s);
		return mav;
	}
	@RequestMapping("/drilldown")
	public ModelAndView drilldown(){
		ModelAndView mav = new ModelAndView();
		mav.setViewName("/highchartsPage/column-drilldown");
		mav.addObject("data", "大家好，我是contact");
		return mav;
	}
	@RequestMapping("/contact2")
	public ModelAndView contact2(){
		
		ModelAndView mav = new ModelAndView();
		mav.setViewName("contact2");
		mav.addObject("data", "大家好，我是contact2");
		return mav;
	}
	
	
	@ResponseBody
	@RequestMapping(value = "tableData")
	public String tableData(HttpServletResponse response,HttpServletRequest request) throws Exception {
		String page = request.getParameter("page");
		TableDataBean bean = null;
		List<TableDataBean> list = new ArrayList<TableDataBean>();
		for(int i=0;i<10;i++){
			bean = new TableDataBean(i);
			list.add(bean);
		}
		String json = new ResponseUtil<TableDataBean>().dealResponse(1, 1, list.size(), list);
		System.out.println(json);
		return json;
	}
	
	@ResponseBody
	@RequestMapping(value = "SubGrid")
	public String SubGrid(HttpServletResponse response,HttpServletRequest request) throws Exception {
		String id = request.getParameter("id");
		SubGridBean bean = null;
		List<SubGridBean> list = new ArrayList<SubGridBean>();
		for(int i=0;i<10;i++){
			bean = new SubGridBean(i);
			list.add(bean);
		}
		String json = new ResponseUtil<SubGridBean>().dealResponse(1, 1, list.size(), list);
		System.out.println(json);
		return json;
	}
	@ResponseBody
	@RequestMapping(value = "TreeGrid")
	public String TreeGrid(HttpServletResponse response,HttpServletRequest request) throws Exception {
		 // TODO Auto-generated method stub
		RequestBean reqBean = RequestUtil.getRequestParam(request);
	    String n_left = request.getParameter("n_left");
	    String xml = "";
	    
	    List<TestBean>  list = new ArrayList<TestBean>();
	    List<TestBean>  subList = new ArrayList<TestBean>();
	    TestBean tb = null;
    	for(int i=0;i<5;i++){
    		tb = new TestBean();
    		tb.setNum("accNum"+i);
    		tb.setAccount("account"+i);
    		tb.setBalance("balance"+i);
    		tb.setCredit("credit"+i);
    		tb.setDebit("debit"+i);
    		tb.setId(i+"");
    		list.add(tb);
    	}
    	for(int i=0;i<3;i++){
    		tb = new TestBean();
    		tb.setNum("accNum"+i);
    		tb.setAccount("account"+i);
    		tb.setBalance("balance"+i);
    		tb.setCredit("credit"+i);
    		tb.setDebit("debit"+i);
    		tb.setId(i+"");
    		subList.add(tb);
    	}
    	
	    //一级数据
	    if(n_left==null || "".equals(n_left)){
	    	//xml = new ResponseUtil<TestBean>().dealResponse(reqBean.getPage(), 1, list.size(), list);
	    	
	    	
	    	
	      xml = "<?xml version='1.0' encoding='utf-8'?>" +
	          "  <rows>" +
	          "    <page>1</page>" +
	          "    <total>1</total>" +
	          "    <records>1</records>" +
	          "    <row>" +
	          "      <cell>1</cell>" +
	          "      <cell>Cash</cell>" +
	          "      <cell>100</cell>" +
	          "      <cell>400.00</cell>" +
	          "      <cell>250.00</cell>" +
	          "      <cell>150.00</cell>" +
	          "      <cell>0</cell>" +
	          "      <cell>1</cell>" +
	          "      <cell>8</cell>" +
	          "      <cell>false</cell>" +
	          "      <cell>false</cell>" +
	          "    </row>" +
	          "    <row>" +
	          "      <cell>5</cell>" +
	          "      <cell>Bank's</cell>" +
	          "      <cell>200</cell>" +
	          "      <cell>1500.00</cell>" +
	          "      <cell>1000.00</cell>" +
	          "      <cell>500.00</cell>" +
	          "      <cell>0</cell>" +
	          "      <cell>9</cell>" +
	          "      <cell>14</cell>" +
	          "      <cell>false</cell>" +
	          "      <cell>false</cell>" +
	          "    </row>" +
	          "    <row>" +
	          "      <cell>8</cell>" +
	          "      <cell>Fixed asset</cell>" +
	          "      <cell>300</cell>" +
	          "      <cell>0.00</cell>" +
	          "      <cell>1000.00</cell>" +
	          "      <cell>-1000.00</cell>" +
	          "      <cell>0</cell>" +
	          "      <cell>15</cell>" +
	          "      <cell>16</cell>" +
	          "      <cell>true</cell>" +
	          "      <cell>false</cell>" +
	          "    </row>" +
	          "  </rows>";
	    }else if("1".equals(n_left)){//二级数据
	    	//xml = new ResponseUtil<TestBean>().dealResponse(reqBean.getPage(), 1, subList.size(), subList);
	      xml = "<?xml version='1.0' encoding='utf-8'?>" +
	          "  <rows>" +
	          "    <page>1</page>" +
	          "    <total>1</total>" +
	          "    <records>1</records>" +
	          "    <row>" +
	          "      <cell>2</cell>" +
	          "      <cell>Cash 1</cell>" +
	          "      <cell>1</cell>" +
	          "      <cell>300.00</cell>" +
	          "      <cell>200.00</cell>" +
	          "      <cell>100.00</cell>" +
	          "      <cell>1</cell>" +
	          "      <cell>2</cell>" +
	          "      <cell>5</cell>" +
	          "      <cell>false</cell>" +
	          "      <cell>false</cell>" +
	          "    </row>" +
	          "    <row>" +
	          "      <cell>4</cell>" +
	          "      <cell>Cash 2</cell>" +
	          "      <cell>2</cell>" +
	          "      <cell>100.00</cell>" +
	          "      <cell>50.00</cell>" +
	          "      <cell>50.00</cell>" +
	          "      <cell>1</cell>" +
	          "      <cell>6</cell>" +
	          "      <cell>7</cell>" +
	          "      <cell>true</cell>" +
	          "      <cell>false</cell>" +
	          "    </row>" +
	          "  </rows>";
	    }else if("2".equals(n_left)){//三级数据
	    	//xml = new ResponseUtil<TestBean>().dealResponse(reqBean.getPage(), 1, subList.size(), subList);
	      xml = "<?xml version='1.0' encoding='utf-8'?>" +
	          "  <rows>" +
	          "    <page>1</page>" +
	          "    <total>1</total>" +
	          "    <records>1</records>" +
	          "    <row>" +
	          "      <cell>3</cell>" +
	          "      <cell>Sub Cash 1</cell>" +
	          "      <cell>1</cell>" +
	          "      <cell>300.00</cell>" +
	          "      <cell>200.00</cell>" +
	          "      <cell>100.00</cell>" +
	          "      <cell>2</cell>" +
	          "      <cell>3</cell>" +
	          "      <cell>4</cell>" +
	          "      <cell>true</cell>" +
	          "      <cell>false</cell>" +
	          "    </row>" +
	          "  </rows>";
	    }
	    System.out.println("-------------"+xml);
	    return xml;
	}
	
	
}